#!/bin/bash
# Copy  recorded programs to portable drive
set -e
source=/var/video/by_date/Default
dest=/media/6506/video/by_date
destjunk=/media/6506/video/watched
ffmpeg=/opt/mythtv/ffmpeg
if [[ ! -d "$dest" ]] ; then
    echo "No copying - $dest is not available"
    exit 2
fi
/opt/mythtv/links.sh
# ffmpeg -i input.ts  -vcodec copy -acodec copy -f vob output.mpg -map 0.0 -map 0.1
cd "$source"
for file in *.mpg ; do
    if [[ ! -f "$dest/$file" ]] ; then
        echo "Copying from $source/$file to $dest/$file ..."
        # $ffmpeg -i "$file"  -vcodec copy -acodec copy -f vob "$dest/$file" -map 0.0 -map 0.1
        cp -Lp "$file" "$dest/$file"
    fi;
done
echo clean up deleted ..
cd "$dest"
for file in *.mpg ; do
    if [[ ! -f "$source/$file" ]] ; then
        echo "Moving from $dest/$file to $destjunk/$file ..."
        mv "$dest/$file" "$destjunk/$file"
    fi;
done

echo Program Listing
ls -1 "$dest"